package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.app.*;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserRemindCommand;
import com.cskaoyan.wordmemorize.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    UserService userService;


    // 获取用户信息
    @GetMapping("info")
    public Result<UserDTO> getUserInfo() {
        Long userId = StpKit.USER.getLoginIdAsLong();
        UserDTO userInfo = userService.getUserInfo(userId);
        return Result.ok(userInfo);
    }


    @GetMapping("level/info")
    public Result<DisplayUserLevelDTO> getUserLevelInfo() {
        long loginIdAsLong = StpKit.USER.getLoginIdAsLong();
        DisplayUserLevelDTO userLevelInfo = userService.getUserLevelInfo(loginIdAsLong);
        return Result.ok(userLevelInfo);
    }


    // TODO:返回用户的升级信息
    @GetMapping("upgrade/info")
    public Result<NextLevelDTO> getUpgradeInformation() {
        long loginIdAsLong = StpKit.USER.getLoginIdAsLong();
        NextLevelDTO userNextDTO = userService.getUserNextDTO(loginIdAsLong);
        return Result.ok(userNextDTO);
    }

    // TODO：单词上限变化明细
    @GetMapping("voc/bound/detail")
    public Result<PageDTO<DisplayUserVocBoundLogDTO>> getWordsChange(PageRequest pageRequest) {
        // userService.getUserVocBoundLog();
        long loginIdAsLong = StpKit.USER.getLoginIdAsLong();
        PageDTO<DisplayUserVocBoundLogDTO> userVocBoundLog = userService.getUserVocBoundLog(pageRequest, loginIdAsLong);
        return Result.ok(userVocBoundLog);
    }

    @GetMapping("voc/bound/statistics")
    public Result<UserVocBoundStatisticsDTO> getWordsStatic() {
        long userId = StpKit.USER.getLoginIdAsLong();
        UserVocBoundStatisticsDTO userVocBoundStatistics = userService.getUserVocBoundStatistics(userId);
        return Result.ok(userVocBoundStatistics);
    }

    @GetMapping("voc/my/page")
    public Result<UserPageDTO> getUserPage() {
        long loginIdAsLong = StpKit.USER.getLoginIdAsLong();
        UserPageDTO userPage = userService.getUserPage(loginIdAsLong);
        return Result.ok(userPage);
    }

    @PutMapping("day/voc")
    public Result reviseReviewWords(@RequestParam Integer count) {
        long loginIdAsLong = StpKit.USER.getLoginIdAsLong();
        userService.updateVocCountOfDay(loginIdAsLong, count);
        return Result.ok();
    }

    @PutMapping("remind")
    public Result reviseRemindTime(@RequestBody UserRemindCommand userRemindCommand) {
        long loginIdAsLong = StpKit.USER.getLoginIdAsLong();
        String string = String.valueOf(loginIdAsLong);
        userRemindCommand.setUserId(string);
        userService.updateUserRemind(userRemindCommand);
        return Result.ok();
    }

}
